import { timeOutFunc } from "@/api/helper/timeOut"
import { Toast } from "@/components/messages"
import { useLocale } from "@/locales"
/**
 * @description: 校验网络请求状态码
 * @param {Number} status
 * @return void
 */
export const checkStatus = (status: number): void => {
	const { formatMessage } = useLocale()
	switch (status) {
		case 400:
			Toast.error(formatMessage({ id: "response.400" }))
			break
		case 401:
			Toast.error(formatMessage({ id: "response.401" }))
			break
		case 403:
			Toast.error(formatMessage({ id: "response.403" }))
			break
		case 404:
			Toast.error(formatMessage({ id: "response.404" }))
			break
		case 405:
			Toast.error(formatMessage({ id: "response.405" }))
			break
		case 408:
			Toast.error(formatMessage({ id: "response.408" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.timeout" })
			})
			break
		case 500:
			Toast.error(formatMessage({ id: "response.500" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.500" })
			})
			break
		case 502:
			Toast.error(formatMessage({ id: "response.502" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.502" })
			})
			break
		case 503:
			Toast.error(formatMessage({ id: "response.503" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.503" })
			})
			break
		case 504:
			// 网关超时
			Toast.error(formatMessage({ id: "response.504" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.504" })
			})
			break
		case 521:
			// 网关错误
			Toast.error(formatMessage({ id: "response.521" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.521" })
			})
			break
		default:
			Toast.error(formatMessage({ id: "response.failed" }))
			timeOutFunc({
				msg: formatMessage({ id: "response.failed" })
			})
	}
}
